
// Definition for singly-linked list.
function ListNode(val) {
    this.val = val;
    this.next = null;
}

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var removeDuplicateNodes = function(head) {
  if(!head || !head.next) return head;
  let map = new Map(), last = head, temp = head.next;
  map.set(last.val, true);
  while(temp) {
    if(map.has(temp.val)) {
      let node = temp;
      last.next = temp.next;
      temp = temp.next;
      delete node;
    } else {
      map.set(temp.val, true);
      last = temp;
      temp = temp.next;
    }
  }
  return head;
};
let head = [1, 2, 3, 3, 2, 1];
